package com.macro.mall.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dto.BmsImportantActivitiesSlideshowParam;
import com.macro.mall.mapper.BmsImportantActivitiesSlideshowMapper;
import com.macro.mall.model.BmsImportantActivitiesSlideshow;
import com.macro.mall.service.BmsImportantActivitiesSlideshowService;
import com.macro.mall.utils.EnumImportant;
import com.macro.mall.utils.UserUtils;


/**
 * 观光车点位图片Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
public class BmsImportantActivitiesSlideshowServiceImpl implements BmsImportantActivitiesSlideshowService {
    @Autowired
    private BmsImportantActivitiesSlideshowMapper bmsImportantActivitiesSlideshowMapper;
    @Autowired
    private UserUtils userUtils;


    /**
     * 分页查询展览活动
     * @return
     */
    @Transactional
    @Override
    public List<BmsImportantActivitiesSlideshow> getList(BmsImportantActivitiesSlideshowParam bmsImportantActivitiesSlideshowParam) {
        PageHelper.startPage(bmsImportantActivitiesSlideshowParam.getPageNum(), bmsImportantActivitiesSlideshowParam.getPageSize());;
        BmsImportantActivitiesSlideshow bmsImportantActivitiesSlideshow = new BmsImportantActivitiesSlideshow();
        BeanUtils.copyProperties(bmsImportantActivitiesSlideshowParam, bmsImportantActivitiesSlideshow);
        List<BmsImportantActivitiesSlideshow> list = bmsImportantActivitiesSlideshowMapper.findAll(bmsImportantActivitiesSlideshow);
        for (BmsImportantActivitiesSlideshow entity : list) {
        	entity.setBusinessTypeName(EnumImportant.getNameByCode(entity.getBusinessType()));
		}
        return list;
    }

    /**
     * 新增展览活动
     * @param
     * @return
     */
    @Transactional
    @Override
    public int create(BmsImportantActivitiesSlideshowParam bmsImportantActivitiesSlideshowParam) {
        int count = 0;
        //获取当前登录用户id
        Long userId = userUtils.getUserId();
        BmsImportantActivitiesSlideshow bmsImportantActivitiesSlideshow = new BmsImportantActivitiesSlideshow();
        BeanUtils.copyProperties(bmsImportantActivitiesSlideshowParam, bmsImportantActivitiesSlideshow);
        bmsImportantActivitiesSlideshow.setCreateUser(userId);
        bmsImportantActivitiesSlideshow.setCreateTime(new Date());
        bmsImportantActivitiesSlideshow.setUpdateUser(userId);
        bmsImportantActivitiesSlideshow.setUpdateTime(new Date());

        count = bmsImportantActivitiesSlideshowMapper.insert(bmsImportantActivitiesSlideshow);

        return count;
    }

    /**
     * 更新展览活动
     * @param
     * @return
     */
    @Transactional
    @Override
    public int update(BmsImportantActivitiesSlideshowParam bmsImportantActivitiesSlideshowParam) {
        int count = 0;
        //获取当前登录用户id
        Long userId = userUtils.getUserId();
        BmsImportantActivitiesSlideshow bmsImportantActivitiesSlideshow = new BmsImportantActivitiesSlideshow();
        BeanUtils.copyProperties(bmsImportantActivitiesSlideshowParam, bmsImportantActivitiesSlideshow);
        bmsImportantActivitiesSlideshow.setUpdateUser(userId);
        bmsImportantActivitiesSlideshow.setUpdateTime(new Date());
        //更新重要活动
        count = bmsImportantActivitiesSlideshowMapper.update(bmsImportantActivitiesSlideshow);
        return count;
    }

    /**
     * 获取展览活动信息
     * @param id
     * @return
     */
    @Override
    public BmsImportantActivitiesSlideshow getItem(Long id) {
        return bmsImportantActivitiesSlideshowMapper.selectById(id);
    }

    /**
     * 删除展览活动
     * @param ids
     * @return
     * 完成
     */
    @Transactional
    @Override
    public int delete(List<Long> ids) {
        return bmsImportantActivitiesSlideshowMapper.delete(ids);
    }
}
